<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>管理菜单信息</title>
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css">
</head>
<body style="background-color: #f0f2f5;">
<div style="padding: 15px;margin: 15px;background-color: #fff;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>菜单信息查询</legend>
    </fieldset>

    <div class="layui-btn-group">
        <button class="layui-btn" id="btn-add">添加菜单</button>
    </div>

    <table class="layui-hide" id = "table1" lay-filter="table1"></table>
</div>

<script type="text/html" id="oper-col">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="add">添加</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="${allServerPath}static/layui/layui/layui.js"></script>

<script>
    layui.config({
        base: '${allServerPath}static/layui/build/js/'
    }).extend({
        treetable: 'treetable-lay/treetable'
    }).use(['layer','table','treetable'], function () {
        var $ = layui.jquery,
            table = layui.table,
            layer = layui.layer,
            treetable = layui.treetable;

        var renderTable = function(){
            layer.load(2);  //加载层
            treetable.render({
                treeColIndex: 1,
                treeSpid: 0,
                treeIdKey: 'id',
                treePidKey: 'pid',
                treeDefaultClose: false,
                treeLinkage: false,
                elem: '#table1',
                url: '${allServerPath}web/syspermission/treedata.htmls?t=' + Date.parse(new Date()),
                page: false,
                cols: [[
                    {type: 'numbers'},
                    {field: 'name', title: '菜单名'},
                    {field: 'id', title: 'id'},
                    {field: 'url', title: '路径'},
                    {field: 'type', title: '类型'},
                    {templet: '#oper-col', title: '操作'}
                ]],
                done: function () {
                    layer.closeAll('loading');
                }
            });
        };
        renderTable();

        //监听工具条
        table.on('tool(table1)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                            url: '${allServerPath}web/syspermission/delete/' + data.id + ".htmls",
                            method: 'get',
                            dataType: 'json',
                            success: function (result) {
                                if (result.success) {
                                    obj.del();
                                    layer.close(index);
                                }
                            },
                            error: function () {
                                layer.msg('删除失败,请稍后重试.');
                            }
                        }
                    );
                });
            } else if (layEvent === 'edit') {
                layer.msg('修改' + data.id);
                layer.open({
                    type: 2,
                    title: '详细信息',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['1000px', '580px'],
                    content: '${allServerPath}web/syspermission/editSysPermission/'+ data.id +'.htmls'
                });
            } else if(layEvent === 'add'){
                layer.msg('添加' + data.id);
                layer.open({
                    type: 2,
                    title: '详细信息',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['1000px', '580px'],
                    content: '${allServerPath}web/syspermission/addSysPermission/'+ data.id +'.htmls'
                });
            }
        });

        $("#btn-add").click(function(){
            layer.open({
                type: 2,
                title: '详细信息',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['1000px', '580px'],
                content: '${allServerPath}web/syspermission/addSysPermission/0.htmls'
            });
        })
    });

</script>
</body>
</html>
